<script>
    $(function () {
        var spread = true;
        $("#fold").click(function () {

            if (spread) {
                $(this).removeClass('glyphicon-step-backward').addClass('glyphicon-th-list');
                $("#mainContent").removeClass('col-sm-10').addClass('col-sm-12');
                spread = false;
            } else {
                spread = true;
                $(this).removeClass('glyphicon-th-list').addClass('glyphicon-step-backward');
                $("#mainContent").removeClass('col-sm-12').addClass('col-sm-10');
            }
            $("#left").animate({width: 'toggle'});
            // $("#left").fadeToggle();
        });
    });

    function delItem() {
        var msg = "你确定要删除吗？";
        if (confirm(msg) == true) {
            return true;
        } else {
            return false;
        }
    }

    function getRowData(item) {
        var myrow = $(item).parent().parent("tr").children("td");
        console.log(myrow)
        var data = [];
        for (let i = 0; i < myrow.length - 1; i++) {
            data.push(myrow[i].innerText)
        }
        console.log(data)
        fillData(data)
    }

    function fillData(data) {
        $("#stuid").attr("value", data[0])
        $("#stuname").attr("value", data[1])
        let gender = data[2];
        // $("input").attr('checked','false')
        if (gender == '女') {
            $("input[value='女']").prop('checked', 'true')
        } else {
            $("input[value='男']").prop('checked', 'true')
        }
        $("#stubirthday").attr("value", data[3]);
        $("#stumajor").val(data[4])


    }

    function addActive(item) {
        $(".pagination").children("li").removeClass("active");
        $(item).parent().addClass("active")
        console.log($(".pagination").children("li"))


    }

    $(function () {
        $("#addBtn").click(function () {
            $("#addStuModal").modal({
                show: true
            })
        })

        $("#addBtn1").click(function () {
            $("#addStuModal").modal({
                show: true
            })
        })
        // 获取当前页码，在分页组件对应项上添加active类
        let currentPage = Number.parseInt( < %= session.getAttribute("currentPage") % >
    )
        console.log("currentPage", currentPage);
        $(".pagination").children("li").removeClass("active");
        console.log($(".current"))
        $(".current").eq(currentPage - 1).addClass("active")

    });
</script>
<div>

    <!-- Nav tabs -->
    <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab"
                                                  data-toggle="tab">学生列表</a></li>
        <li role="presentation">
            <a id="addBtn1">添加学生</a>
        </li>
    </ul>


    <!-- Tab panes -->
    <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="home">
            <table class="table table-bordered table-hover table-striped" style="margin-top: 10px">
                <tr>
                    <th>学号</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>出生日期</th>
                    <th>专业</th>
                    <th>操作</th>
                </tr>


            </table>

            <ul class="list-unstyled">
                <li>
                    <button class="btn btn-success" id="addBtn" data-toggle="modal" data-target="#addStuModal">添加学生信息</button>
                </li>
            </ul>
            <div class="pull-right">
                <nav aria-label="Page navigation">
                    <ul class="pagination">
                        <li><a href="stu?method=list&page=1" onmouseleave="addActive(this)">1</a></li>
                        <li><a href="stu?method=list&page=2" onmouseleave="addActive(this)">2</a></li>
                        <li><a href="stu?method=list&page=3" onmouseleave="addActive(this)">3</a></li>
                        <li><a href="stu?method=list&page=4">4</a></li>
                        <li><a href="stu?method=list&page=5">5</a></li>

                    </ul>
                </nav>
            </div>
        </div>
        <div role="tabpanel" class="tab-pane" id="profile">...</div>

    </div>

</div>
<!--添加学生的对话框-->
<div class="modal fade" id="addStuModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">添加学生</h4>
            </div>
            <div class="modal-body">
                <form action="stu" method="post">
                    <input type="hidden" name="method" value="add">
                    <div class="form-group">
                        <label for="name">姓名</label>
                        <input type="text" class="form-control" id="name" name="name" placeholder="姓名" required>
                    </div>
                    <div class="form-group" style="margin-bottom: 0">
                        <label for="gender">性别</label>
                    </div>
                    <label class="radio-inline">
                        <input type="radio" name="gender" checked value="男"> 男
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="gender" value="女"> 女
                    </label>
                    <div class="form-group">
                        <label for="birthday">生日</label>
                        <input type="date" class="form-control" id="birthday" value="1988-06-01"
                               name="birthday" placeholder="生日">
                    </div>
                    <div class="form-group" style="margin-bottom: 0">
                        <label for="major">专业</label>
                    </div>
                    <select multiple class="form-control" id="major" name="major">
                        <option selected>软件工程</option>
                        <option>计算机科学技术</option>
                        <option>英语</option>
                        <option>声乐</option>
                        <option>表演艺术</option>
                    </select>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">确认添加</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消添加</button>
                    </div>

                </form>
            </div>

        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!--更新学生的对话框-->
<div class="modal fade" id="updateStuModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">更新学生信息</h4>
            </div>
            <div class="modal-body">
                <form action="stu" method="post">
                    <input type="hidden" name="method" value="update">
                    <input type="hidden" name="id" value="update" id="stuid">
                    <div class="form-group">
                        <label for="stuname">姓名</label>
                        <input type="text" class="form-control" id="stuname" name="name" placeholder="姓名">
                    </div>
                    <div class="form-group" style="margin-bottom: 0">
                        <label for="gender">性别</label>
                    </div>
                    <label class="radio-inline">
                        <input type="radio" name="gender" id="gender" value="男"> 男
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="gender" value="女"> 女
                    </label>
                    <div class="form-group">
                        <label for="stubirthday">生日</label>
                        <input type="date" class="form-control" id="stubirthday" name="birthday" placeholder="生日">
                    </div>
                    <div class="form-group" style="margin-bottom: 0">
                        <label for="stumajor">专业</label>
                    </div>
                    <select multiple class="form-control" id="stumajor" name="major">
                        <option>软件工程</option>
                        <option>计算机科学技术</option>
                        <option>英语</option>
                        <option>声乐</option>
                        <option>表演艺术</option>
                    </select>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">确认修改</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消修改</button>
                    </div>

                </form>
            </div>

        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->